package x

import (
	"fmt"
	"gitee.com/injoyai/goutil/g/gf"
	"gitee.com/injoyai/goutil/g/gin"
	"gitee.com/injoyai/goutil/g/in"
	"gitee.com/injoyai/goutil/i/html"
	"gitee.com/injoyai/goutil/net/router"
	"log"
	"net/http"
)

// NewGo 原生服务
func NewGo(port int, fn http.HandlerFunc) error {
	log.Printf("开启HTTP服务(:%d)成功...\n", port)
	return http.ListenAndServe(fmt.Sprintf(":%d", port), in.InitGo(fn))
}

// NewGf gf框架(单例模式,内存占用大)
func NewGf(port int) *gf.Server {
	return gf.New(port)
}

// NewGin gin框架
func NewGin(port int) *gin.Server {
	return gin.New(port)
}

// NewRouter 自写
func NewRouter(port int) *router.Server {
	s := router.New().SetPort(port)
	in.InitRoute(s)
	s.BindCodeHandler(404, func(r *router.Request) {
		r.WriteString(html.PageNotFindRobot)
	})
	return s
}
